package com.ooolong.expression.operator;

import com.ooolong.expression.OObject;

public class Equal extends Operator {

	public Equal() {
		super("=", 1, false);
	}

	@Override
	public OObject execute(OObject[] args) {
		if (args.length != 2) {
			throw new RuntimeException();
		}

		OObject leftOprand = args[0];
		OObject rightOprand = args[1];

		if (leftOprand == null || rightOprand == null) {
			throw new RuntimeException();
		}

		if (!leftOprand.isNumber() || !rightOprand.isNumber()) {
			throw new RuntimeException();
		}

		boolean res = false;
		if (leftOprand.isFloat() || rightOprand.isFloat()) {
			res = leftOprand.toDouble().equals(rightOprand.toDouble());
		} else {
			res = leftOprand.toLong().equals(rightOprand.toLong());
		}
		return OObject.newInstance(res);
	}
}
